**********************************  
* Alternative democracy measures *
**********************************

clear 
 ***graphs
 
   set scheme s2color 

 
eststo clear

* rescale libdem indices

   

 local coefficientofinterest `"  "libdem_extra_vdem"   "polyarchy_extra_vdem" "partipdem_extra_vdem"  "delibdem_extra_vdem" "egaldem_extra_vdem"    "' 

 
 clear
foreach x of local  coefficientofinterest {

use "Temp/Master_5yr.dta"

 forvalues r=1/7{
	 gen  mb_ub_SPEC`r'=.
	 gen mb_p_SPEC`r'=.	
	 gen mb_lb_SPEC`r'=.

}
 
 
eststo mb_dom_`x': reghdfe dtax_non_trade_real      `x'   l1_gov_change         , absorb(year iso_n) cluster(   iso_n) level(90) // Canonical variables only
 capture replace mb_ub_SPEC1= _b[`x']  + _se[`x']*invttail(e(df_r), 0.05)    
 capture replace mb_p_SPEC1= _b[`x']  										 
 capture replace mb_lb_SPEC1=_b[`x']  - _se[`x']*invttail(e(df_r), 0.05) 	   
 
 

eststo mb_dom_int_`z': reghdfe dtax_non_trade_real      `x'    l1_gov_change   l1_civ_war_all_PRIO   l1_int_war_all_PRIO , absorb(year iso_n) cluster(   iso_n) level(90) // international conflict
capture  replace mb_ub_SPEC2= _b[`x']  + _se[`x']*invttail(e(df_r), 0.05) 
capture  replace mb_p_SPEC2= _b[`x']  
capture  replace mb_lb_SPEC2=_b[`x']  - _se[`x']*invttail(e(df_r), 0.05) 
 
  
eststo mb_res_`x': reghdfe dtax_non_trade_real      `x'  l1_gov_change   l1_civ_war_all_PRIO   l1_int_war_all_PRIO   P_ind_total_f_realshare  , absorb(year iso_n) cluster(   iso_n)  level(90) // resources
capture  replace mb_ub_SPEC3= _b[`x']  + _se[`x']*invttail(e(df_r), 0.05) 
capture  replace mb_p_SPEC3= _b[`x']  
capture  replace mb_lb_SPEC3=_b[`x']  - _se[`x']*invttail(e(df_r), 0.05) 
 
  

eststo mb_aid_`x': reghdfe dtax_non_trade_real      `x'   l1_gov_change   l1_civ_war_all_PRIO   l1_int_war_all_PRIO  S_g5_unw_alliance_abs  , absorb(year iso_n) cluster(   iso_n) level(90) // aid
capture  replace mb_ub_SPEC4= _b[`x']  + _se[`x']*invttail(e(df_r), 0.05) 
capture  replace mb_p_SPEC4	= _b[`x']  
capture  replace mb_lb_SPEC4=_b[`x']  - _se[`x']*invttail(e(df_r), 0.05) 
 
  
eststo mb_cr_`x': reghdfe dtax_non_trade_real       `x'  l1_gov_change   l1_civ_war_all_PRIO   l1_int_war_all_PRIO   cr_market_accessXBOEinv  , absorb(year iso_n) cluster(   iso_n) level(90) // capital markets
capture  replace mb_ub_SPEC5= _b[`x']  + _se[`x']*invttail(e(df_r), 0.05) 
capture  replace mb_p_SPEC5= _b[`x']  
capture  replace mb_lb_SPEC5=_b[`x']  - _se[`x']*invttail(e(df_r), 0.05) 
 
  

eststo mb_f_`x':  reghdfe dtax_non_trade_real          `x'  l1_gov_change   l1_civ_war_all_PRIO   l1_int_war_all_PRIO 	 P_ind_total_f_realshare   S_g5_unw_alliance_abs   cr_market_accessXBOEinv    , absorb(year iso_n) cluster(   iso_n) level(90) // full specification
capture  replace mb_ub_SPEC6= _b[`x']  + _se[`x']*invttail(e(df_r), 0.05) 
capture  replace mb_p_SPEC6= _b[`x']  
capture  replace mb_lb_SPEC6=_b[`x']  - _se[`x']*invttail(e(df_r), 0.05) 
 
  
eststo mb_fc_`x': reghdfe dtax_non_trade_real       `x'   l1_gov_change   l1_civ_war_all_PRIO   l1_int_war_all_PRIO P_ind_total_f_realshare  S_g5_unw_alliance_abs   cr_market_accessXBOEinv X_* l1.drought_affected_merged  , absorb(year iso_n) cluster(  iso_n)  level(90) // full specification, controls
capture  replace mb_ub_SPEC7= _b[`x']  + _se[`x']*invttail(e(df_r), 0.05) 
capture  replace mb_p_SPEC7= _b[`x']  
capture  replace mb_lb_SPEC7=_b[`x']  - _se[`x']*invttail(e(df_r), 0.05) 
 
    
 keep mb_*
  keep if _n==1
 
 gen variable="`x'"
 
 
save "TEMP/res_dem_`x'"    ,replace

  
 
}
  
 clear all
 
  
foreach x of local  coefficientofinterest {

append using "TEMP/res_dem_`x'"


}

 


 

  
 
 

 forvalues z=1/7{
		gen e_point_SPEC`z'=  .
		gen e_lb_SPEC`z'=.
		gen e_ub_SPEC`z'=. 
}


 forvalues z=1/7{

	foreach y of local  coefficientofinterest {
 		replace e_point_SPEC`z'=  mb_p_SPEC`z'   	if variable=="`y'"
		replace e_lb_SPEC`z'=mb_lb_SPEC`z'			if variable=="`y'"
		replace e_ub_SPEC`z'=mb_ub_SPEC`z' 			if variable=="`y'"
		}
		
		
}


 

keep e_*   variable

 reshape long e_point_SPEC  e_lb_SPEC  e_ub_SPEC , i(   variable) j(SPEC)  string
	 
 destring SPEC, replace
 
 rename  e_point_SPEC 	y 
 rename  e_lb 			yl  
 rename  e_ub  			yu 
 
 
 
 gen variable_n=.

 
 
 replace variable_n=1 if variable=="libdem_extra_vdem"
				replace variable_n=2 if variable=="polyarchy_extra_vdem"
				replace variable_n=3 if variable=="partipdem_extra_vdem"
				replace variable_n=4 if variable=="delibdem_extra_vdem"
				replace variable_n=5 if variable=="egaldem_extra_vdem"
				
				
 sort variable_n
 
separate y, by(variable_n)
separate yu	, by(variable_n)
separate yl	, by(variable_n)
 
 
  
 ** democracy coefficient
 
 
 
				
				
				
				
				
				label var y1 "Liberal Democracy Score"
				label var y2 "Electoral Democracy Score"
				label var y3 "Participatory Democracy Score"
				label var y4 "Deliberative Democracy Score"
				label var y5 "Egalitarian Democracy Score"
				
				* do not show w/o controls
				
					replace SPEC=. if SPEC==6
					replace SPEC=6 if SPEC==7
					
					
				gen graph_position=SPEC*10+variable_n

 
				label  define x     11  "libdem_extra_vdem"  12 "polyarchy_extra_vdem" 13 "partipdem_extra_vdem"  14 "delibdem_extra_vdem" 15 "egaldem_extra_vdem" ///
									21  "libdem_extra_vdem"  22 "polyarchy_extra_vdem" 23 "partipdem_extra_vdem"  24 "delibdem_extra_vdem" 25 "egaldem_extra_vdem" ///
									31  "libdem_extra_vdem"  32 "polyarchy_extra_vdem" 33 "partipdem_extra_vdem"  34 "delibdem_extra_vdem" 35 "egaldem_extra_vdem" ///
									41  "libdem_extra_vdem"  42 "polyarchy_extra_vdem" 43 "partipdem_extra_vdem"  44 "delibdem_extra_vdem" 45 "egaldem_extra_vdem" ///
									51  "libdem_extra_vdem"  52 "polyarchy_extra_vdem" 53 "partipdem_extra_vdem"  54 "delibdem_extra_vdem" 55 "egaldem_extra_vdem" ///
									61  "libdem_extra_vdem"  62 "polyarchy_extra_vdem" 63 "partipdem_extra_vdem"  64 "delibdem_extra_vdem" 65 "egaldem_extra_vdem"  
					*				71  "libdem_extra_vdem"  72 "polyarchy_extra_vdem" 73 "partipdem_extra_vdem"  74 "delibdem_extra_vdem" 75 "egaldem_extra_vdem" 
						
							 
							 
				label  value  graph_position x 

				 rename graph_position x
							 
				local group1 SPEC
				local group2 variable
				twoway (scatter y1 x , msymbol(Sh) msize(medium)  xsize(8) ) ///
					   (rcap yu1 yl1 x)  ///
					   (scatter y2 x , msymbol(Oh) msize(large)) ///
					   (rcap yu2 yl2 x )  ///
					   (scatter y3 x , msymbol(T) msize(medium)) ///
					   (rcap yu3 yl3 x )  ///
					   (scatter y4 x , msymbol(D) msize(medium)) ///
					   (rcap yu4 yl4 x )  ///
					   (scatter y5 x , msymbol(S) msize(medium)) ///
					   (rcap yu5 yl5 x), scheme(lean1) 			///
					   xlabel(11 "Canonical" 21 "Canonical incl. wars" 31 "Resources" 41 "Aid" 51 "Credit access" 61 "Full"  , angle(45)) xtitle("Specification")   ///
					   ytitle(Coefficient) yline(0, lpattern(dash))  ///
					   legend( order(  1  3  5  7 9)  position(3) row(6) ring(100) title("Legend", size(medsmall)))  
					    
					   
					  
					graph save  "Temp/Coefficient_DIFFERENTVDEM" , replace 
					graph export  "Output/Graphs/Appendix/APP_FIG_5_5.pdf" , replace 
 
